'''
线程加锁：
1、导入库：
import threading
2、创建锁对象
lock = threading.Lock()

lock.acquire()  # 等待获得锁阻塞
....这中间写获得锁之后的执行的任务代码
lock.release()  # 执行完任务之后要释放锁

但是加锁之后速度就变慢了
'''

import threading
import time

lock = threading.Lock()

list1 = [0] * 10
def task1():
	lock.acquire()
	for i in range(len(list1)):
		time.sleep(0.5)
		list1[i] = 1
		
	lock.release()
	

def task2():
	lock.acquire()
	for i in range(len(list1)):
		print('----------',list1[i])
		
	lock.release()
	
	
if __name__ == '__main__':
	t1 = threading.Thread(target=task1)
	t2 = threading.Thread(target=task2)
	
	t2.start()
	t1.start()
	
	
	t1.join()
	t2.join()
	print(list1)